/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Action;

import ActionForm.mobClienteRegistrarActionForm;
import ActionForm.mobClientesActionForm;
import BE.Cliente;
import BE.Ocurrencia;
import BE.Usuarioventas;
import BE.Visita;
import BL.ClienteBL;
import BL.OcurrenciaBL;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.actions.LookupDispatchAction;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import java.util.*;
import javax.servlet.http.HttpSession;

/**
 *
 * @author dennis
 */
public class mobClientesAction extends LookupDispatchAction {
    
    /* forward name="success" path="" */
    private final static String SUCCESS = "success";
    
    /** Provides the mapping from resource key to method name.
     * @return Resource key / method name map.
     */
    protected Map getKeyMethodMap() {
      Map map = new HashMap();
      map.put("button.Buscar", "buscarCliente");
//      map.put("button.edit", "edit");
//      map.put("button.delete", "delete");
      return map;
    }
    
    /** Action called on Add button click
     */
    public ActionForward buscarCliente(ActionMapping mapping,
          ActionForm form,
          HttpServletRequest request,
          HttpServletResponse response) throws java.lang.Exception {

        mobClientesActionForm objClienteForm = new mobClientesActionForm(request);

        if (objClienteForm.getStrIdCliente()==-1)
        {
        request.setAttribute("strMensaje", "Campo codigo solo acepta caracteres numéricos");
        return mapping.findForward("buscarCliente");
        }

        HttpSession session = request.getSession();

        Cliente objClienteBE = new Cliente(objClienteForm);

        ClienteBL objClienteBL = new ClienteBL();

        //jcguzmanr Mayo 27
        Ocurrencia objOcurrenciaBE = new Ocurrencia();
        OcurrenciaBL objOcurrenciaBL = new OcurrenciaBL();

        objOcurrenciaBE.setBoolClienteesta(true);
        objOcurrenciaBE.setCvDescripcion("");
        objOcurrenciaBE.setCvNombre("");

        List<Ocurrencia> arrOcurrenciaEsta = objOcurrenciaBL.buscarOcurrenciaMovilEsta(objOcurrenciaBE);
        List<Ocurrencia> arrOcurrenciaNoEsta = objOcurrenciaBL.buscarOcurrenciaMovilNoEsta(objOcurrenciaBE);
        request.setAttribute("arrOcurrenciaEsta",arrOcurrenciaEsta);
        request.setAttribute("arrOcurrenciaNoEsta",arrOcurrenciaNoEsta);
        //


        List<Cliente> arrClientes = objClienteBL.buscarCliente(objClienteBE);

        if((arrClientes!=null)&&(arrClientes.size()>0))
        {
        request.setAttribute("arrClientes", arrClientes);
        return mapping.findForward("mostrarCliente");
        
        }
        else
        {
        request.setAttribute("strMensaje", "No se obtuvo resultados");
        return mapping.findForward("buscarCliente");
        }

//        if(!boolRegistrado)
//        session.setAttribute("strMsjDescripcion", "No se pudo registrar al Cliente, Intentelo de nuevo");
//        else
//        session.setAttribute("strMsjDescripcion", "Cliente Registrado");

//      return mapping.findForward("mostrarCliente");
    }
        
    /* And your JSP would have the following format for submit buttons:

        <html:form action="/test">
            <html:submit property="method">
              <bean:message key="button.add"/>
            </html:submit>
            <html:submit property="method">
              <bean:message key="button.edit"/>
            </html:submit>
            <html:submit property="method">
              <bean:message key="button.delete"/>
            </html:submit>
        </html:form>
    */

    
    
}